<template>
	<view class="sort-detail">
		<view class="sort-detail__table">
			<view class="table-tr">
				<view class="table-th">仓库信息</view>
				<view class="table-th">订单份数</view>
				<view class="table-th">订单数量</view>
				<view class="table-th noBorder">分拣数量</view>
			</view>
			<view class="table-tr" v-for="(item, index) in tableList" :key="index" @click="toSubmitSort(item)">
				<view class="table-td">{{ item.warehouseName }}</view>
				<view class="table-td">{{ item.count }}</view>
				<view class="table-td">{{ item.orderWeight  }}</view>
				<view class="table-td noBorder">{{ item.weight || '' }}</view>
			</view>
		</view>

		<view v-if="isShowOneKeyBtn && type==0" class="tui-clock" @tap="oneKeySort()">

			<button class="tui-button-primary" hover-class="tui-button-hover" type="primary">一键分拣</button>

		</view>
	</view>
</template>

<script>
	import {
		disKeySort
	} from '@/apis/user'
	export default {
		data() {
			return {
				type: '',
				goodsid: '',
				tableList: [],
				isShowOneKeyBtn: false,
				shopId: '',
			}
		},
		onLoad(options) {
			console.info(options)
			this.goodsid = options.goodsId
			this.shopId = options.shopId
			this.type = options.type
			console.log(this.type);
			this.getList()
		},
		methods: {

			async getList() {
				const data = await this.$apis.dis.listDetails({
					parentId: this.goodsid
				})
				this.tableList = data.data
				if (this.tableList.length > 0) {
					//sta 1 显示 2 不显示
					this.isShowOneKeyBtn = this.tableList[0].sta === '1' ? true : false
				}

			},
			toSubmitSort(item) {
				let params = {
					recPic: item.recPic,
					name: item.name,
					unitPrice: item.unitPrice,
					code: item.code,
					warehouseName: item.warehouseName,
					sortingWeight: item.orderWeight,
					count: item.count,
					weight: item.weight,
					id: item.id
				}
				uni.navigateTo({
					url: '/pages/dissubmit/index?params=' + JSON.stringify(params) + '&id=' + this.goodsid
				})
			},
			oneKeySort() {
				uni.showModal({
					title: '提示',
					content: '确认分拣吗？',
					success: (res) => {
						if (res.confirm) {
							this.oneKeySortSmiut()
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});

			},
			oneKeySortSmiut: function() {
				let that = this;
				disKeySort(that.shopId)
					.then(res => {
						// console.log(res)
						// this.$yrouter.back();
						uni.navigateBack()
					})
					.catch(err => {
						console.log(err)
						uni.showToast({
							title: err.msg,
							icon: 'none',
							duration: 2000,
						})
					})
			}
		}
	}
</script>

<style scoped lang="scss">
	.sort-detail {
		width: 100%;
		min-height: 100vh;
		background: #F6F6F6;
	}

	.tui-clock {
		width: 100%;
		position: fixed;
		left: 0;
		bottom: 100rpx;
		z-index: 999;
		padding: 20rpx 25rpx 30rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.sort-detail__table {
		width: 100%;

		.table-tr {
			border-top: 1px solid #E2E2E2;
			display: flex;
			align-items: center;
			background: #FFFFFF;
		}

		.table-th,
		.table-td {
			text-align: center;
			flex: 1;
			word-break: break-all;
			text-overflow: ellipsis;
			display: -webkit-box;
			-webkit-box-orient: vertical;
			-webkit-line-clamp: 1;
			overflow: hidden;
			border-right: 1px solid #E2E2E2;

			&.noBorder {
				border-right: none;
			}
		}

		.table-th {
			padding-top: 20rpx;
			padding-bottom: 18rpx;
			background: #F3FFF6;
			font-size: 30rpx;
			font-weight: bold;
			color: #666666;
		}

		.table-td {
			padding: 0rpx 26rpx;
			background: #FFFFFF;
			font-size: 32rpx;
			font-weight: bold;
			color: #333333;
			line-height: 80rpx;
		}
	}
</style>